package com.qqtech.qquan.coupon.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.coupon.dao.CouponBaseDao;
import com.qqtech.qquan.coupon.enums.CouponBaseBizzTypeDictEnum;
import com.qqtech.qquan.coupon.model.CouponBase;
import com.qqtech.qquan.coupon.model.CouponBaseQuery;
import com.qqtech.qquan.coupon.model.CouponBaseVo;

import jersey.repackaged.com.google.common.collect.Lists;

@Service
public class CouponBaseServiceImpl extends BaseServiceImpl<CouponBase>
		implements CouponBaseService {
	public static final Logger log = LoggerFactory.getLogger(CouponBaseServiceImpl.class);
	
	@Resource
	private CouponBaseDao couponBaseDao;

	@Override
	protected BaseDao<CouponBase> getBaseDao() {
		return couponBaseDao;
	}

	@Override
	public int updateMinusQuantity(Integer id, Integer quantity) {
		if (id == null || quantity == null || quantity.intValue() < 0) {
			return 0;
		}
		return couponBaseDao.updateMinusQuantity(id,quantity);
	}

	@Override
	public int updateIsNull(Integer id) {
		return couponBaseDao.updateIsNull(id);
	}
	
	@Override
	public List<Integer> getCouponIdsByBizzType(CouponBaseBizzTypeDictEnum couponBaseBizzType){
		List<Integer> couponIds = Lists.newArrayList();
		if(couponBaseBizzType==null){
			return couponIds;
		}
		CouponBaseQuery couponBaseQ = new CouponBaseQuery();
		couponBaseQ.setBizzType(couponBaseBizzType.getCode());
		Pageable pageKit = new PageKit(1, Integer.MAX_VALUE, new PageOrder(Direction.ASC, "id"));
		List<CouponBaseVo> couponBaseVoList = couponBaseDao.queryList(couponBaseQ, pageKit);
		if(couponBaseVoList!=null && couponBaseVoList.size()>0){
			for(CouponBaseVo coupon : couponBaseVoList){
				couponIds.add(coupon.getId());
			}
		}
		return couponIds;
	}
	
}